use sea_orm::entity::prelude::*;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "lineage_suggestions")]
pub struct Model {
    #[sea_orm(primary_key)]
    pub id: i64,
    pub child_id: i64,
    pub suggested_parent_id: i64,
    pub confidence_score: f64,
    pub suggestion_reason: String,
    pub detection_method: String,
    pub status: String,
    pub created_at: DateTime,
    pub reviewed_at: Option<DateTime>,
    pub reviewed_by: Option<i64>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
    #[sea_orm(
        belongs_to = "super::data_items::Entity",
        from = "Column::ChildId",
        to = "super::data_items::Column::Id"
    )]
    Child,
    #[sea_orm(
        belongs_to = "super::data_items::Entity",
        from = "Column::SuggestedParentId",
        to = "super::data_items::Column::Id"
    )]
    SuggestedParent,
    #[sea_orm(
        belongs_to = "super::users::Entity",
        from = "Column::ReviewedBy",
        to = "super::users::Column::Id"
    )]
    Reviewer,
}

impl Related<super::data_items::Entity> for Entity {
    fn to() -> RelationDef {
        Relation::Child.def()
    }
}

impl ActiveModelBehavior for ActiveModel {}
